package person.bing.fbcloud.leetcode;

import java.util.Arrays;

/**
 * @author: mengfanbing
 * @date: 2020/12/25 9:47
 */
public class Q455 {
    public static void main(String[] args) {
        int[] g = {1,2,3};
        int[] s = {1,2,4,5};
        int contentChildren = findContentChildren(g, s);
        System.out.println(contentChildren);
    }

    public static int findContentChildren(int[] g, int[] s) {
        int ans = 0;
        Arrays.sort(g);
        Arrays.sort(s);

        int gLength = g.length;
        int sLength = s.length;
        int gIndex = 0;
        int sIndex = 0;
        while (gIndex < gLength && sIndex < sLength){
            if (s[sIndex] >= g[gIndex]){
                gIndex++;
                sIndex++;
                ans++;
            }else {
                sIndex++;
            }
        }
        return ans;
    }
}
